package com.foreknow.controller;

import com.foreknow.model.GuestBook;
import com.foreknow.service.GuestBookService;
import com.foreknow.service.impl.GuestBookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GuestBookService service = new GuestBookServiceImpl();
        GuestBook gb = new GuestBook();
        gb.setId(Integer.parseInt(req.getParameter("id")));
        int id = gb.getId();
        gb.setName(req.getParameter("name"));
        gb.setPhone(req.getParameter("phone"));
        gb.setEmail(req.getParameter("email"));
        gb.setTitle(req.getParameter("title"));
        gb.setContent(req.getParameter("content"));
//        List<GuestBook> list = new ArrayList<>();
//        list.add(gb);
        service.gUpdate(gb, id);
//        //重定向
//        resp.sendRedirect(req.getContextPath()+"/ManagerServlet");

        //显示所有留言信息（转发）
        req.getRequestDispatcher("/ManagerServlet?q=list").forward(req,resp);
    }
}
